package com.library.mapper;

import com.github.pagehelper.Page;
import com.library.annotation.AutoFill;
import com.library.entity.BookTag;
import com.library.enumeration.OperationType;
import com.library.vo.BookTagVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookTagMapper {
    /**
     * 添加标签
     * @param bookTag
     */
    @Insert("insert into book_tag(user_id, book_id, name, description, create_time, update_time) " +
            "values" +
            "(#{userId}, #{bookId}, #{name}, #{description}, #{createTime}, #{updateTime})"
            )
    @AutoFill(value = OperationType.INSERT)
    void insert(BookTag bookTag);

    @AutoFill(value = OperationType.UPDATE)
    void update(BookTag bookTag);

    @Select("select * from book_tag where book_id = #{bookId} and user_id = #{userId}")
    List<BookTagVO> getTags(Long bookId, Long userId);

    Page<BookTagVO> searchTags(String keyword);

    @Delete("delete from book_tag where book_id = #{bookId} and id = #{tagId}")
    void deleteById(Long bookId, Long tagId);
}
